unit QExport4MSOfficeCommon;

interface

uses
  Classes;

type
  TMSCellAlignment = (caLeft, caRight, caCenter, caJustify); //caJustify = WrapText for Excel 2007
  TMSCellVerticalAligment = (cvaTop, cvaMiddle, cvaBottom);
  TMSStripStyleType = (ssNone, ssColumn, ssRow);
  TXlsxBorderStyle = (xbsThin, xbsDashed, xbsDashDot, xbsDashDotDot, xbsDotted, xbsHair,
                    xbsDouble, xbsThick, xbsMedium, xbsMediumDashed, xbsMediumDashDot,
                    xbsSlantDashDot, xbsMediumDashDotDot);
                    
  TDocxBorderStyle = (dbsSingle, dbsThick, dbsDouble, dbsHairline, dbsDot,
                      dbsDashLargeGap, dbsDotDash, dbsDotDotDash, dbsTriple,
                      dbsThinThickSmallGap, dbsThickThinSmallGap, dbsThinThickThinSmallGap,
                      dbsThinThickMediumGap, dbsThickThinMediumGap, dbsThinThickThinMediumGap,
                      dbsThinThickLargeGap, dbsThickThinLargeGap, dbsThinThickThinLargeGap,
                      dbsWave, dbsDoubleWave, dbsDashSmallGap, dbsDashDotStroker, dbsEmboss3D,
                      dbsEngrave3D);

  TMSHighlightColor = (hcNone,
    hcYellow, hcGreen, hcCyan, hcMagenta, hcBlue,
    hcRed, hcDarkBlue, hcDarkCyan, hcDarkGreen, hcDarkMagenta,
    hcDarkRed, hcDarkYellow, hcDarkGray, hcLightGray, hcBlack);

function MSHighlightColorToStr(Color: TMSHighlightColor): WideString;
function MSCellAlignmentToStr(CellAlignment: TMSCellAlignment): WideString; overload;
function MSCellAlignmentToStr(CellAlignment: TMSCellVerticalAligment): WideString; overload;
function MSBorderStyleToStr(Style: TXlsxBorderStyle): WideString; overload;
function MSBorderStyleToStr(Style: TDocxBorderStyle): WideString; overload;
function ReplaceSymbols(var Value: WideString): WideString;

implementation

uses QExport4EmsWideStrUtils;

function ReplaceSymbols(var Value: WideString): WideString;
var
  p, i: Integer;
const
  SearchSym: array [0..4] of WideString = ('&', '>', '<', '"', ' ');
  ReplSym: array [0..4] of WideString = ('&amp;', '&gt;', '&lt;', '&quot;', '&#160;');
begin
  for i := 0 to Length(SearchSym) - 1 do
  begin
    p := 1;
    while p > 0 do
    begin
      p := WideStringPosEx(SearchSym[i], Value, p);
      if p > 0 then
      begin
        Delete(Value, p, 1);
        Insert(ReplSym[i], Value, p);
        Inc(p, 4);
      end;
    end;
  end;
  Result := Value;
end;

function MSHighlightColorToStr(Color: TMSHighlightColor): WideString;
begin
  Result := '';
  case Color of
    hcYellow:
      Result := 'yellow';
    hcGreen:
      Result := 'green';
    hcCyan:
      Result := 'cyan';
    hcMagenta:
      Result := 'magenta';
    hcBlue:
      Result := 'blue';
    hcRed:
      Result := 'red';
    hcDarkBlue:
      Result := 'darkBlue';
    hcDarkCyan:
      Result := 'darkCyan';
    hcDarkGreen:
      Result := 'darkGreen';
    hcDarkMagenta:
      Result := 'darkMagenta';
    hcDarkRed:
      Result := 'darkRed';
    hcDarkYellow:
      Result := 'darkYellow';
    hcDarkGray:
      Result := 'darkGray';
    hcLightGray:
      Result := 'lightGray';
    hcBlack:
      Result := 'black';
  end;
end;

function MSCellAlignmentToStr(CellAlignment: TMSCellAlignment): WideString;
begin
  Result := '';
  case CellAlignment of
    caLeft:
      Result := 'left';
    caCenter:
      Result := 'center';
    caRight:
      Result := 'right';
  end;
end;

function MSCellAlignmentToStr(CellAlignment: TMSCellVerticalAligment): WideString;
begin
  Result := '';
  case CellAlignment of
    cvaTop:
      Result := 'top';
    cvaMiddle:
      Result := 'center';
    cvaBottom:
      Result := 'bottom';
  end;
end;

function MSBorderStyleToStr(Style: TXlsxBorderStyle): WideString;
begin
  Result := '';
  case Style of
    xbsThin:
      Result := 'thin';
    xbsDashed:
      Result := 'dashed';
    xbsDashDot:
      Result := 'dashDot';
    xbsDashDotDot:
      Result := 'dashDotDot';
    xbsDotted:
      Result := 'dotted';
    xbsHair:
      Result := 'hair';
    xbsDouble:
      Result := 'double';
    xbsThick:
      Result := 'thick';
    xbsMedium:
      Result := 'medium';
    xbsMediumDashed:
      Result := 'mediumDashed';
    xbsMediumDashDot:
      Result := 'mediumDashDot';
    xbsSlantDashDot:
      Result := 'slantDashDot';
    xbsMediumDashDotDot:
      Result := 'mediumDashDotDot';
  end;
end;

function MSBorderStyleToStr(Style: TDocxBorderStyle): WideString; overload;
begin
  Result := '';
  case Style of
    dbsSingle:
      Result := 'single';
    dbsThick:
      Result := 'thick';
    dbsDouble:
      Result := 'double';
    dbsHairline:
      Result := 'hairline';
    dbsDot:
      Result := 'dot';
    dbsDashLargeGap:
      Result := 'dashLargeGap';
    dbsDotDash:
      Result := 'dotDash';
    dbsDotDotDash:
      Result := 'dotDotDash';
    dbsTriple:
      Result := 'triple';
    dbsThinThickSmallGap:
      Result := 'thinThickSmallGap';
    dbsThickThinSmallGap:
      Result := 'thickThinSmallGap';
    dbsThinThickThinSmallGap:
      Result := 'thinThickThinSmallGap';
    dbsThinThickMediumGap:
      Result := 'thinThickMediumGap';
    dbsThickThinMediumGap:
      Result := 'thickThinMediumGap';
    dbsThinThickThinMediumGap:
      Result := 'thinThickThinMediumGap';
    dbsThinThickLargeGap:
      Result := 'thinThickLargeGap';
    dbsThickThinLargeGap:
      Result := 'thickThinLargeGap';
    dbsThinThickThinLargeGap:
      Result := 'thinThickThinLargeGap';
    dbsWave:
      Result := 'wave';
    dbsDoubleWave:
      Result := 'doubleWave';
    dbsDashSmallGap:
      Result := 'dashSmallGap';
    dbsDashDotStroker:
      Result := 'dashDotStroker';
    dbsEmboss3D:
      Result := 'emboss3D';
    dbsEngrave3D:
      Result := 'engrave3D';
  end;
end;

end.
